<template>
	<view class="prohibition">
		<view class="demo" :style="[{color},{height},{paddingTop},{background:transparent?'transparent':null}]">
			<!-- 左侧返回按钮 -->
			<view class="buttonView" @click="onBack" v-if="back"
				:style="[{color},{height},{width},{right:left},{top}]">
				<uni-icons class="borders" :style={width:width} type="arrowleft" size="20" :color='color'></uni-icons>
				<uni-icons :style={width:width} type="home-filled" size="20" :color='color'></uni-icons>
				<!-- 此处图标使用的是 uni-ui图标 -->
			</view>
			<!-- 中间标题文字 -->
			<view class="title">
				{{title}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				height: 0,
				paddingTop: 0,
				width: 0,
				left: 0,
				top: 0,
			}
		},
		// props: ["title", "back"],
		props: {
			title: { // 标题文字(默认为空)
				type: String,
				default: ''
			},
			color: { // 标题和返回按钮颜色(默认白色)
				type: String,
				default: '#fff'
			},
			back: { // 是否显示返回按钮(不传值默认不显示)
				type: Boolean,
				default: true
			},
			transparent: { // 是否透明
				type: Boolean,
				default: false
			}
		},

		mounted() {
			const demo = uni.getMenuButtonBoundingClientRect()
			// console.log(demo)
			this.height = demo.height + "px"
			this.paddingTop = demo.top + "px"
			this.width = demo.width + 'px'
			this.left = demo.left + 'px'
			this.top = demo.top +'px'
			uni.setNavigationBarColor({
				frontColor:'#ffffff',
				backgroundColor:'#00000055'
			})
		},
		methods: {
			// 左侧返回按钮调用
			onBack() {
				uni.navigateBack()
			},
			onHome(){
				uni.navigateBack(999)
			}
		}
	}
</script>
<style lang="less">
	.prohibition {
		position: sticky;
		top: 0;
		z-index: 9999;
	}

	.demo {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		z-index: 100;
		padding-bottom: 10rpx;
		background: linear-gradient(90deg,
				#f9d923,
				#00a19d,
				#0c87b7,
				#cb49ff,
				#ff6666,
				#f9d923);
		background-size: 1000%;
		// box-shadow: 0 0 15px rgb(2, 4, 24);
		animation: glow 60s linear forwards infinite;

		@keyframes glow {
			from {
				background-position: 0%;
			}

			to {
				background-position: 1000%;
			}
		}

		.buttonView {
			position: absolute;
			display: flex;
			justify-content: space-around;
			align-items: center;
			color: #fff;
			background: rgba(0, 0, 0, 0.3);
			border: solid 1rpx rgba(255, 255, 255, 0.3);
			border-radius: 100vw;

			.borders {
				border-right: solid 1rpx rgba(255, 255, 255, 0.3);
			}
			
			uni-icons{
				text-align: center;
			}
		}

		.title {
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			// color: #FFFFFF;
			font-weight: 700;
		}
	}
</style>
